<template>
  <div class="box8">
    <div class="title">
      <p>类型统计</p>
      <img src="../../images/dataScreen-title.png" alt="" />
    </div>
    <div class="charts" ref="charts"></div>
  </div>
</template>

<script setup lang="ts">
import * as echarts from 'echarts'
import { ref, onMounted } from 'vue'
import { ReqTypeData } from '@/api/screen'
//获取DOM节点
let charts = ref()
let Typedata = ref()
let arr
//组件挂载完毕
onMounted(async () => {
  await getData()
  await init()
})
const init = () => {
  //一个容器可以同时展示多种类型的图形图标
  let mychart = echarts.init(charts.value)
  let option = {
    title: {
      text: '电影类型统计',
      textStyle: {
        color: 'white',
      },
    },
    legend: {
      data: ['电影类型'],
    },
    radar: {
      // shape: 'circle',
      indicator: [
        { name: '科技', max: 150 },
        { name: '犯罪', max: 150 },
        { name: '灾难', max: 150 },
        { name: '爱情', max: 150 },
        { name: '动作', max: 150 },
        { name: '情节', max: 160 },
      ],
    },
    series: [
      {
        name: 'Budget vs spending',
        type: 'radar',
        data: [
          {
            value: arr,
          },
        ],
      },
    ],
  }
  //设置配置项
  mychart.setOption(option)
}
const getData = async () => {
  let res = await ReqTypeData()
  Typedata.value = res.data
  //取出Typedata中的value  形成一个数组
  arr = Object.values(Typedata.value)
}
</script>

<style scoped lang="scss">
.box8 {
  width: 100%;
  height: 100%;
  background: url(../../images/dataScreen-main-cb.png) no-repeat;
  background-size: 100% 100%;
  margin-top: 20px;

  .title {
    p {
      color: white;
      font-size: 18px;
    }
  }

  .charts {
    height: calc(100% - 30px);
  }
}
</style>
